#include <stdio.h>
#include <string>
#include <iostream>
#include <exception>

#include <execinfo.h>
#include <signal.h>
#include <stdlib.h>

#include "GenericException.hpp"

GenericException::GenericException(const std::string& location, int line, const std::string& function, const std::string& text) {
	this->location = location;
	this->line = line;
	this->function = function;
	this->text = text;
}

std::string GenericException::getFullText() const {
	std::stringstream Strm;
	Strm << location << ":" << line << " [" << function << "]: " << text;
	return Strm.str();
}

std::string GenericException::getText() const {
	return text;
}

void GenericException::terminate() const {
	std::cerr << (*this);
	abort();
}

std::ostream& operator<<(std::ostream &Strm, const GenericException &Obj) {
	Strm << "Exception at " << Obj.location << ", line " << Obj.line << std::endl;
	Strm << "     At: " << Obj.function << std::endl;
	Strm << "     Reason: " << Obj.text << std::endl;
	return Strm;
}

GenericException::~GenericException() throw() {
}

